package com.qf.bank.dealprovider.controller;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.bank.dealapi.po.TransferAccounts;
import com.qf.bank.dealprovider.service.ITransferAccountsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 徐毫杰
 * @since 2019-12-06
 */
@RestController
public class TransferAccountsController {
    @Autowired
    private ITransferAccountsService service;
    /**
     * 分页
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public IPage<TransferAccounts> page(@RequestParam int current, @RequestParam int size) {
        IPage<TransferAccounts> page = service.page(new Page<>(current, size));
        return page;
    }
    /**
     * 增加转账记录
     */
    @RequestMapping(value = "/", method = RequestMethod.POST)
    public Boolean setInsert(@RequestBody TransferAccounts transferAccounts){
        boolean result = service.save(transferAccounts);
        return result;
    }
    /**
     * 删除转账记录
     */
    @RequestMapping(value = "/{transferAccountsId}", method = RequestMethod.DELETE)
    public Boolean getDeleteId(@PathVariable(value = "transferAccountsId") int transferAccountsId) {
        Boolean result = service.removeById(transferAccountsId);
        return result;
    }
    /**
     * 删除多个转账
     */
    @RequestMapping(value = "/",method = RequestMethod.DELETE)
    public Boolean getDelete(@RequestBody List<Integer> list){
        boolean result = service.removeByIds(list);
        return result;
    }
    /**
     * 修改转账记录
     */
    @RequestMapping(value = "/", method = RequestMethod.PATCH)
    public Boolean getChangeId(@RequestBody TransferAccounts transferAccounts) {
        boolean result = service.updateById(transferAccounts);
        return result;
    }
    /**
     * 查询转账记录
     */
    @RequestMapping(value = "/{transferAccountsId}", method = RequestMethod.GET)
    public TransferAccounts getById(@PathVariable(value = "transferAccountsId") int transferAccountsId) {
        TransferAccounts user = service.getById(transferAccountsId);
        return user;
    }
}
